package com.wlr.blog.web.common.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wlr.blog.web.common.entity.Admin;
import com.wlr.blog.web.common.mapper.AdminMapper;
import com.wlr.blog.web.common.service.AdminService;
import com.wlr.blog.web.common.vo.AdminVo;
import com.wlr.blog.web.common.vo.Permission;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 *
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    @Autowired
    AdminMapper adminMapper;

    @Override
    public boolean login(Admin admin) {
        Admin result = adminMapper.selectOne(new QueryWrapper<Admin>().eq("user_name", admin.getUserName()).eq("password", admin.getPassword()));
        return ObjectUtils.isNotEmpty(result);
    }

    @Override
    public Admin getById(Serializable id) {
        Admin byId = super.getById(id);
        AdminVo adminVo = new AdminVo();
        BeanUtils.copyProperties(byId, adminVo);
        List<Permission> permission = new ArrayList<>();
        permission.add(new Permission("主控台", "dashboard_console"));
        permission.add(new Permission("监控页", "dashboard_monitor"));
        permission.add(new Permission("工作台", "dashboard_workplace"));
        permission.add(new Permission("基础列表", "basic_list"));
        permission.add(new Permission("基础列表删除", "basic_list_delete"));
        adminVo.setToken("tokenTest");
        adminVo.setPermissions(permission);
        return adminVo;
    }
}
